# Contributor: Duncan Bellamy <dunk@denkimushi.com>
# Contributor: Daniel Sabogal <dsabogalcc@gmail.com>
# Maintainer: Duncan Bellamy <dunk@denkimushi.com>
pkgname=octave
pkgver=7.1.0
pkgrel=3
pkgdesc="A high-level language, primarily intended for numerical computations"
url="https://www.gnu.org/software/octave/"
# ppc64le, s390x missing texlive
# missing openjdk on riscv64
arch="all !s390x !riscv64 !ppc64le"
license="GPL-3.0-or-later"
subpackages="$pkgname-dev $pkgname-doc"

case "$CARCH" in
	x86)
		#x86 libjava.so cannot find libjvm.so
		options="!check" ;;
esac

makedepends="
	arpack-dev
	autoconf
	automake
	bison
	curl-dev
	fftw-dev
	fltk-dev
	fontconfig-dev
	freetype-dev
	gfortran
	ghostscript-dev
	glpk-dev
	glu-dev
	gnuplot
	graphicsmagick-dev
	hdf5-dev
	imagemagick-dev
	java-jdk
	lcms2-dev
	libltdl
	libsm-dev
	libsndfile-dev
	libtool
	openblas-dev
	pcre-dev
	perl
	pkgconf
	portaudio-dev
	qhull-dev
	qrupdate-dev
	qscintilla-dev
	qt5-qttools-dev
	rapidjson-dev
	readline-dev
	suitesparse-dev
	texinfo
	texlive
	texlive-dvi
	xz-dev
	zip
	zlib-dev
	"
source="https://ftp.gnu.org/gnu/octave/octave-$pkgver.tar.xz
	abs.patch
	test.patch
	fix-resource-manager-get_codecs.patch
	"

prepare() {
	default_prepare
	autoreconf -vif
}

build() {
	export JAVA_HOME="/usr/lib/jvm/default-jvm"
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--infodir=/usr/share/info \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--enable-shared \
		--disable-static \
		--disable-rpath
	make
}

check() {
	LD_LIBRARY_PATH="/usr/lib/jvm/default-jvm/lib/server:$LD_LIBRARY_PATH" make check
}

package() {
	make DESTDIR="$pkgdir/" \
		-C "$builddir" install
	rm -rf "$pkgdir"/usr/lib/charset.alias
	rm -rf "$pkgdir"/usr/share/octave/"$pkgver"/etc/tests
}

sha512sums="
f315cfa4dfb1f8d8b0ff96ee636a330d833d9e8d308ec4dbe139b520086fe99b5ef12f3fa6cee770e2fbe468e27559ae7b14f0d77a64c970f5bf34be4ab6c213  octave-7.1.0.tar.xz
f6cd1a52686a66d9914029b3c70eba88d2468700abfb16c3bdc5c0bae2a29cbf06143e15c2828be1112d45403247ff5713edf1b1261eaf132465ac05df6c7c7c  abs.patch
a2d67ead53701c74c5837cb79cf82e93a40eec58d41bf73b07d40ecf9655d8b358ae245745a613335abd42d4954b2c41309392bbb423fa2bdd61a848079cb173  test.patch
405a0bc6e8ebec3f1baf7f34389ca05985a443525885ff5e5460214d4d3e4451048f1f84fab9056f8115bd19d51c24e4666d1ea23f457861591b4cc52ccdf14b  fix-resource-manager-get_codecs.patch
"
